package com.yunban.project.api.text_check.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunban.project.api.text_check.domain.CorrectionConfig;
import com.yunban.project.api.text_check.enums.CorrectionModel;
import com.yunban.project.api.text_check.mapper.CorrectionConfigMapper;
import com.yunban.project.api.text_check.service.CorrectionConfigService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: lijiajun
 * @date: 2024-11-20
 * @version: 1.0
 */
@Service
public class CorrectionConfigServiceImpl extends ServiceImpl<CorrectionConfigMapper, CorrectionConfig> implements CorrectionConfigService {
    @Override
    public List<CorrectionConfig> getEnabledConfigList() {
        LambdaQueryWrapper<CorrectionConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CorrectionConfig::isEnabled, true);
        // 优先级排序
        wrapper.orderByAsc(CorrectionConfig::getOrder, CorrectionConfig::getId);
        return this.list(wrapper);
    }

    @Override
    public CorrectionConfig findByCode(CorrectionModel model) {
        LambdaQueryWrapper<CorrectionConfig> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(CorrectionConfig::isEnabled, true);
        wrapper.eq(CorrectionConfig::getCode, model);
        return this.getOne(wrapper, false);
    }
}
